const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    type: 'month',
    charges: []
  },
  onLoad(e){
    let that = this;
    let school_id = wx.getStorageSync('school_id')
    that.$data.type = e.type;
    wx.showLoading({
      title: '加载中...',
    })
    let url = app.globalData.api + '/api/v1.0/report/charge/' + school_id + '/' + e.type;
    that.$http.get(url, { token: wx.getStorageSync('token') }).then((res) => {
      if (res.data.code == 0) {
        that.$data.charges = res.data.data;
      } else if (res.data.code == 10001) {
        wx.navigateTo({
          url: "/pages/common/authorize/index"
        })
      }else {
        that.$data.charges = [];
      }
      wx.hideLoading();
    }).catch(err => {
      console.log(err.status, err.message);
    });
  }
})